#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QFileInfo>
#include <QFileDialog>
#include <QMessageBox>
#include <QDialog>
#include <QFocusEvent>
#include <QDateTime>

#include "common.h"
#include "format.h"
#include "jsonhandle.h"
#include "dialogs/createprojectdialog.h"
#include "dialogs/addcabposdialog.h"
#include "dialogs/addscreendialog.h"
#include "dialogs/helpdialog.h"
#include "mytabwidget.h"
#include "observer/globalobserver.h"

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    void addScreen(Screen add_screen);
    void addPartition(int screen_id, Partition add_partition);
    void addLayout(int screen_id, int partition_id, Layout add_layout);
    void addItem(int screen_id, int partition_id, int layout_id, Item add_item);
    void addCabPosItem(int screen_id, int partition_id, int layout_id, int item_id, QString cab_pos_item_str, CabPosItem add_cabpositem);

protected:
    void mousePressEvent(QMouseEvent *event);
    void keyPressEvent(QKeyEvent *event);

private slots:
    void on_pushButton_close_clicked();
    void on_pushButton_create_clicked();
    void on_pushButton_open_clicked();

    void on_pushButton_save_clicked();

    void initTreeWidget(Format *format);
    void initTabWidget(Format *format);

    void on_tabWidget_currentChanged(int index);
    void on_item_select(int screen_id, int partition_id, int layout_id, int item_id, QString cab_pos_item_str);
    void on_layout_select(int screen_id, int partition_id, int layout_id);
    void on_partition_select(int screen_id, int partition_id);
    void on_screen_select(int screen_id);

    void on_updateData();

    void on_action_triggered_help();

    void on_action_preview_triggered();

public slots:
    //void addScreen(Screen one_screen);
    void on_treeScreenSelected(int screen_id);
    void on_treePartitionSelected(int screen_id, int partition_id);
    void on_treeLayoutSelected(int screen_id, int partition_id, int layout_id);
    void on_treeItemSelected(int screen_id, int partition_id, int layout_id, int item_id, QString cab_pos_item_str);

    void on_addScreen();
    void on_delScreen(int screen_id);
    void on_addPartition(int screen_id);
    void on_delPartition(int screen_id, int partition_id);
    void on_addLayout(int screen_id, int partition_id);
    void on_delLayout(int screen_id, int partition_id, int layout_id);
    void on_addItem(int screen_id, int partition_id, int layout_id);
    void on_delItem(int screen_id, int partition_id, int layout_id, int item_id);
    void on_addCabPos(int screen_id, int partition_id, int layout_id, int item_id);
    void on_delCabPos(int screen_id, int partition_id, int layout_id, int item_id, QString cab_pos_item_str);

private:
    Ui::MainWindow *ui;

    //E:/lcd-platetype-edit/SuS1/SuS1.json
    QString m_project_full_path;
    //E:/lcd-platetype-edit/SuS1/
    QString m_project_path;

    //板式数据结构类对象
    Format *m_format;

    QString format_type;

    //json处理对象
    JsonHandle m_json_handle;

    //加载完成标志
    bool m_load_flag;

    HelpDialog *m_help_dialog;
};

#endif // MAINWINDOW_H
